import 'package:app/common/app_theme.dart';
import 'package:app/common/colors.dart';
import 'package:app/common/tool.dart';
import 'package:app/components/base_scaffold_appbar.dart';
import 'package:app/pages/car_modules/my_car_detail_module/my_car_detail_model.dart';
import 'package:app/services/address.dart';
import 'package:app/services/dio_manager.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../../utils/search_module.dart';
class MyCarDetailPage extends StatefulWidget {

  var car_case_id;


   MyCarDetailPage(this.car_case_id,{Key? key}) : super(key: key);

  @override
  State<MyCarDetailPage> createState() => _MyCarDetailPageState();
}

class _MyCarDetailPageState extends State<MyCarDetailPage> {


  MyCarDetailModel? model;
  
  requestData()async{
    var json = await DioManager().
    kkRequest('${Address.oaCarsCasesRead}/${widget.car_case_id}',method: 'get');
    MyCarDetailModel detailModel = MyCarDetailModel.fromJson(json);
    model = detailModel;
    setState(() {

    });
  }
  requestDataWithUnlink(var car_case_id)async{
    var params = {
      'car_case_id':car_case_id,
    };
    var json = await DioManager().kkRequest(Address.carsUnlink,bodyParams:params);
    if(json['errmsg'] == 'ok'){
      Get.back(result: 'refresh');
    }
    BotToast.showText(text: json['message']);
  }
  
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    requestData();
  }
  
  
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColor.bgColor,
      appBar: BaseAppBar(
        preferredSize: Size(Get.width, AppTool.appBarHEIGHT),
        child: Text('详情'),
      ),
      body:SafeArea(
          bottom: false,
          child:  Column(
        children: [
          Expanded(child: ListView(
            children: [
              Container(
                  height: 45,
                  color: Colors.white,
                  alignment: Alignment.centerLeft,
                  margin: EdgeInsets.only(top: 20),
                  padding: EdgeInsets.only(left: 15,right: 15),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text('车辆名称',style: appThemeData.textTheme.subtitle1!.copyWith(fontSize: 15),),
                      Text('${model?.data?.carName??''}',style: appThemeData.textTheme.bodyText1!.copyWith(fontSize: 15),),
                    ],
                  )
              ),
              SizedBox(height: 1,),
              Container(
                height: 45,
                color: Colors.white,
                alignment: Alignment.centerLeft,
                padding: EdgeInsets.only(left: 15,right: 15),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text('车牌',style: appThemeData.textTheme.subtitle1!.copyWith(fontSize: 15),),
                    Text('${model?.data?.carNumber??''}',style: appThemeData.textTheme.bodyText1!.copyWith(fontSize: 15),),
                  ],
                ),
              ),
              SizedBox(height: 1,),

              Container(
                height: 45,
                color: Colors.white,
                alignment: Alignment.centerLeft,
                padding: EdgeInsets.only(left: 15,right: 15),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text('厂牌型号:',style: appThemeData.textTheme.subtitle1!.copyWith(fontSize: 15),),
                    Text('${model?.data?.carModel??''}',style: appThemeData.textTheme.bodyText1!.copyWith(fontSize: 15),),
                  ],
                ),
              ),
              SizedBox(height: 1,),

              Container(
                height: 45,
                color: Colors.white,
                alignment: Alignment.centerLeft,
                padding: EdgeInsets.only(left: 15,right: 15),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text('车辆类型',style: appThemeData.textTheme.subtitle1!.copyWith(fontSize: 15),),
                    Text('${model?.data?.carType??''}',style: appThemeData.textTheme.bodyText1!.copyWith(fontSize: 15),),
                  ],
                ),
              ),
              SizedBox(height: 1,),

              Container(
                height: 45,
                color: Colors.white,
                alignment: Alignment.centerLeft,
                padding: EdgeInsets.only(left: 15,right: 15),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text('申请人',style: appThemeData.textTheme.subtitle1!.copyWith(fontSize: 15),),
                    Text('${model?.data?.applicantName??''}',style: appThemeData.textTheme.bodyText1!.copyWith(fontSize: 15),),
                  ],
                ),
              ),
              SizedBox(height: 20,),

              Container(
                height: 45,
                color: Colors.white,
                alignment: Alignment.centerLeft,
                padding: EdgeInsets.only(left: 15,right: 15),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text('出发地',style: appThemeData.textTheme.subtitle1!.copyWith(fontSize: 15),),
                    Text('${model?.data?.placeStart??''}',style: appThemeData.textTheme.bodyText1!.copyWith(fontSize: 15),),
                  ],
                ),
              ),
              SizedBox(height: 1,),
              Container(
                height: 45,
                color: Colors.white,
                alignment: Alignment.centerLeft,
                padding: EdgeInsets.only(left: 15,right: 15),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text('目的地',style: appThemeData.textTheme.subtitle1!.copyWith(fontSize: 15),),
                    Text('${model?.data?.placeEnd??''}',style: appThemeData.textTheme.bodyText1!.copyWith(fontSize: 15),),
                  ],
                ),
              ),

              SizedBox(height: 1,),
              Container(
                height: 45,
                color: Colors.white,
                alignment: Alignment.centerLeft,
                padding: EdgeInsets.only(left: 15,right: 15),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text('紧急程度',style: appThemeData.textTheme.subtitle1!.copyWith(fontSize: 15),),
                    Text('${model?.data?.urgency??''}',style: appThemeData.textTheme.bodyText1!.copyWith(fontSize: 15),),
                  ],
                ),
              ),
              SizedBox(height: 1,),
              Container(
                height: 45,
                color: Colors.white,
                alignment: Alignment.centerLeft,
                padding: EdgeInsets.only(left: 15,right: 15),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text('开始时间',style: appThemeData.textTheme.subtitle1!.copyWith(fontSize: 15),),
                    Text('${model?.data?.timeStart??''}',style: appThemeData.textTheme.bodyText1!.copyWith(fontSize: 15),),
                  ],
                ),
              ),

              SizedBox(height: 1,),
              Container(
                height: 45,
                color: Colors.white,
                alignment: Alignment.centerLeft,
                padding: EdgeInsets.only(left: 15,right: 15),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text('结束时间',style: appThemeData.textTheme.subtitle1!.copyWith(fontSize: 15),),
                    Text('${model?.data?.timeEnd??''}',style: appThemeData.textTheme.bodyText1!.copyWith(fontSize: 15),),
                  ],
                ),
              ),

            ],
          ),),

          SizedBox(
            width: Get.width,
            height: 45+MediaQuery.of(context).padding.bottom,
            child: MaterialButton(elevation: 0,
              onPressed: (){
                SearchModule.confirmDialog(Get.overlayContext!,(){

                  Get.back();

                  requestDataWithUnlink(model?.data?.id);

                });

              },child: Text('删除',style: TextStyle(color: Colors.red,fontSize: 18),),color: Colors.white,),
          )

        ],
      ))
    );
  }
}
